package com.controller;

import com.model.UserModel;
import com.service.UserService;
import com.utils.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author lizhenzhong
 * @date 2018/9/5
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    /**
     *  test
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/test",  produces = "application/json; charset=utf-8")
    public String test(){
        log.info("TestController->test");
        return "Hello world!";
    }

    /**
     * hello
     * @return
     */
    @RequestMapping(value = "/hello")
    @ResponseBody
    public String hello(){
        log.info("TestController->hello");
        return "What the fucking day!";
    }

    /**
     * 查询详情
     * @return
     */
    @RequestMapping(value = "/user")
    @ResponseBody
    public String user(){
//        log.info("TestController->user");
        UserModel user = this.userService.getDetails(1);
        return JsonUtil.toJsonString(user);
    }

    /**
     * 查询列表
     * @return
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public String getList(){
        log.info("TestController->list");
        UserModel queryModel = new UserModel();
        List<UserModel> list = this.userService.list(queryModel);
        return JsonUtil.toJsonString(list);
    }
}
